package dao.caminhoneiro;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import entidade.caminhoneiro.Frete;
import entidade.caminhoneiro.Lance;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import apresentacao.caminhoneiro.Activity_Menu_Principal;


public class AsyncTask_Finalizar_Frete extends AsyncTask<Void, Void, String>{
	private ProgressDialog progress;
	Context context;
	Frete frete;
	
	private String SERVER = "http://nome-produtor.rhcloud.com/caminhoneiro_finalizar_lance/";
	
	public AsyncTask_Finalizar_Frete(Frete frete, Context context){
		this.frete = frete;
		this.context = context;
	}
	
	@Override
	protected String doInBackground(Void... params) {
		try {
			
			PostRequest req = new PostRequest(SERVER);
			req.addParam("id_frete", String.valueOf(frete.getId()) );
			return req.doPostRequest().readLine();
		} catch (Exception e) {
			return e.toString();
		}
	}

	
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		progress.dismiss();
		if(result.equals("OK")){
			Toast.makeText(context, "Frete finalizado!", Toast.LENGTH_SHORT).show();
		}else{
			Toast.makeText(context, result, Toast.LENGTH_SHORT).show();
		}
	}
	
	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
		progress = ProgressDialog.show(context, "Finalizando Frete", "Em progresso...");
	
	}
}
